#!/usr/bin/python
# -*- coding:utf-8 -*-
# project : python_web
# user :taihe
# Author: 冀恩开
# createtime :2018/8/2 15:33
import json

from python_web.tools.mysql import getDB


class ReturnJ(json.JSONEncoder):
    def __init__(self):
        #由于存在setattr,此处必须采用这种方式赋值
        self.__dict__['res'] = {
            'code': 200,
            'msg': '请求成功!'
        }

    def toJson(self):
        return json.dumps(self.res, ensure_ascii=False)

    def __setattr__(self, key, val):
            self.res[key] = val

if __name__ == "__main__":
    ret = ReturnJ()
    mysql = getDB()
    sqlAll = "select * from Choice_question where id=%s" % (1)
    print(sqlAll)
    result,c = mysql.getAll(sqlAll)
    a = result[0].pop('create_time')

    result = result[0]
    print(result)
    ret.result = result
    print (ret.toJson())




